***2020 American National Election Time-Series Study***
clear

use "anes_timeseries_2020_stata_20220210.dta"

*Create Partisanship Variable*
recode V201231x (-9/-8=.)(1=0 "Strong Democrat")(2=1 "Weak Democrat")(3=2 "Lean Democrat")(4=3 "Independent")(5=4 "Lean Republican")(6=5 "Weak Republican")(7=6 "Strong Republican"), gen(republican)
recode republican (0/2=0 "Democrat")(3=1 "Independent")(4/6=2 "Republican"), gen(gop3)

*Create Ideology Variable* 
recode V201200 (-9 -8=.)(1=0 "very liberal")(2=1 "liberal")(3=2 "lean liberal")(4 99=3 "moderate")(5=4 "lean conservative")(6=5 "conservative")(7=6 "very conservative"), gen(conservative)

*Create Education Variable*
recode V201511x (-9/-2=.) (1=0 "no diploma")(2=1 "HS Diploma")(3=2 "some college")(4=3 "B.A. degree")(5=4 "graduate degree"), gen (educ)

*Create Gender Variable*
gen female=.
replace female=0 if V201600==1
replace female=1 if V201600==2

*Create Age Variable*
recode V201507x (-9=.), gen (age)

*Create Population Weight Variable *
rename V200010b weight

*Create White Feeling Thermometer Variable*
recode V202482 (-9/-4=.), gen(whitefeels)
gen whitefeels_nrm = whitefeels/100

*Create Rural Feeling Thermometer Variable*
recode V202184 (-9/-4=.)(998 999=.), gen (ruralfeels)
gen ruralfeels_nrm = ruralfeels/100

*Create Black stereotype variable*
recode V202516 (-9/-5=.)(1=0)(2=1)(3=2)(4=3)(5=4)(6=5)(7=6), gen(blklazy)
recode V202522 (-9/-5=.)(1=0)(2=1)(3=2)(4=3)(5=4)(6=5)(7=6), gen(blkviolent)
gen black_stereotype=(blklazy+blkviolent)
gen black_stereotype_nrm = black_stereotype/12

recode V202515 (-9/-5=.)(1=0)(2=1)(3=2)(4=3)(5=4)(6=5)(7=6), gen(wytlazy)
recode V202521 (-9/-5=.)(1=0)(2=1)(3=2)(4=3)(5=4)(6=5)(7=6), gen(wytviolent)
gen white_stereotype=(wytlazy+wytviolent)

gen prejudice=(black_stereotype-white_stereotype)+12
gen prejudice_nrm = prejudice/24
sum prejudice_nrm

*Create Geographic ID Variable*
recode V202355 (-9/-5=.) (1=0 "Rural")(2=1 "Small Town")(3=2 "Suburb")(4=3 "City"), gen (urban)
recode V202356 (-9/-5=.)(5=.)(1=0 "city person")(2=1 "suburb person")(3=2 "Small-town person")(4=3 "rural person"), gen (ruralid)
recode ruralid (0 1=0)(2 3=1), gen(alt_rural2)

*Create Strength of Geographic ID Variable*
recode V202357 (-9/-1=.)(1=0)(2=1)(3=2)(4=3)(5=4), gen(geo_strength)
gen geo_strength_nrm = geo_strength/4

*Create Nonwhite Variable
gen nonwhite=.
replace nonwhite=0 if V201549x==1
replace nonwhite=1 if V201549x==2
replace nonwhite=1 if V201549x==3
replace nonwhite=1 if V201549x==4
replace nonwhite=1 if V201549x==5
replace nonwhite=1 if V201549x==6

*Create White Consciousness Variable*
recode V202499x (-9/-1=.) (5=0)(4=1)(3=2)(2=3)(1=4), gen(whiteident)
recode V202487 (-9/-5=.)(5=0)(4=1)(3=2)(2=3)(1=4), gen(whitejob)
recode V202483 (-9/-1=.)(5=0)(4=1)(3=2)(2=3)(1=4), gen(changelaws)
gen white_grievance=(whiteident+whitejob+changelaws)
alpha whiteident whitejob changelaws if nonwhite == 0, item std
gen white_grievance_nrm = white_grievance/12
sum white_grievance_nrm

*Create Place Resentment/Empathy Measure (version 1)*
recode V202276x (-7/-2=.)(1=0)(2=1)(3=2)(4=3)(5=4)(6=5)(7=6), gen(rural1)
recode V202279x (-7/-2=.)(1=0)(2=1)(3=2)(4=3)(5=4)(6=5)(7=6), gen(rural2) 
recode V202282x (-7/-2=.)(1=0)(2=1)(3=2)(4=3)(5=4)(6=5)(7=6), gen(rural3) 
gen resent_empathy1=rural1+rural2+rural3
alpha rural1 rural2 rural3 if nonwhite == 0, item std
gen resent_empathy1_nrm = resent_empathy1 /18
sum resent_empathy1_nrm



**************************************************************
**************************************************************
*EMPIRICAL ANALYSIS            -           EMPIRICAL ANALYSIS*
**************************************************************
**************************************************************


************************************************************
*Statistic 1 Endorsement of Rural Areas getting Left Behind*
************************************************************
gen resent_empathy_present = .
replace resent_empathy_present = 1 if resent_empathy1 >= 12
replace resent_empathy_present = 0 if resent_empathy1 < 12
mean resent_empathy_present if nonwhite==0, over (alt_rural2)


*******************************************************
*Statistic 2 Empathy Among White non-rural identifiers *
*******************************************************
gen above_neutral = .
replace above_neutral = 1 if resent_empathy1_nrm >= .5
replace above_neutral = 0 if resent_empathy1_nrm < .5
mean above_neutral if nonwhite==0, over (alt_rural2)


**************************************************************************************************
*Figure 1 Average Levels of Resentful and Empathetic Beliefs About Anti-Rural Geographic Inequity*
**************************************************************************************************
graph bar resent_empathy1_nrm if nonwhite==0,  over (alt_rural2) ytitle("")  ylabel(,angle(horizontal)) graphregion(color(white)) yscale(range(0 1)) ylabel(#5) asyvars bar(1, color(gray)) bar(2, color(black)) bargap(16) legend(label(2 "Resentment")) legend(label(1 "Empathy")) 
graph export Figure1.png

sum resent_empathy1_nrm if nonwhite==0
sum resent_empathy1_nrm if nonwhite==0 & alt_rural2 == 1
sum resent_empathy1_nrm if nonwhite==0 & alt_rural2 == 0


*****************************************************************************
*Figure 2 Kernel Density Distributions of Place-based Resentment and Empathy*
*****************************************************************************
twoway (kdensity resent_empathy1_nrm if alt_rural2==0 & nonwhite==0, lpattern(dash) lcolor(gray)) (kdensity resent_empathy1_nrm if alt_rural2==1, lcolor(black)), ytitle("") xtitle("") ylabel(,angle(horizontal)) graphregion(color(white)) legend(label(2 "Resentment")) legend(label(1 "Empathy"))
graph export Figure2.png

*******************************************************************************************
* Table A1 Difference in Levels of Place Empathy between White and non-White Respondents  *
*******************************************************************************************
reg resent_empathy1_nrm nonwhite if ruralid!=3 [pweight= weight]

******************************************************************************************
* Table A2 Feelings Towards Whites as Predictors of Place Empathy, by Respondent Race    *
******************************************************************************************
reg resent_empathy1_nrm whitejob if alt_rural2==0 & nonwhite==1 [pweight= weight]
reg resent_empathy1_nrm whitejob if alt_rural2==0 & nonwhite==0 [pweight= weight]
reg resent_empathy1_nrm whitefeels_nrm if alt_rural2==0 & nonwhite==1 [pweight= weight]
reg resent_empathy1_nrm whitefeels_nrm if alt_rural2==0 & nonwhite==0 [pweight= weight]

************************************************************
*Table 1 and Table A3 Regression Results (without Ideology)*
************************************************************

*All respondents
reg resent_empathy1_nrm white_grievance_nrm prejudice_nrm c.alt_rural2##c.geo_strength_nrm   i.gop3 i.educ female age if nonwhite==0 [pweight= weight]

*Non-rural identifiers
reg resent_empathy1_nrm white_grievance_nrm prejudice_nrm geo_strength_nrm   i.gop3 i.educ female age [pweight= weight] if alt_rural2==0 & nonwhite==0

*Rural identifiers
reg resent_empathy1_nrm white_grievance_nrm prejudice_nrm geo_strength_nrm   i.gop3 i.educ  female age [pweight= weight] if alt_rural2==1 & nonwhite==0



*********************************************************************
*Figure 3 Effect of Racial Prejudice on Place-Based Resentment*
*********************************************************************
reg resent_empathy1_nrm white_grievance_nrm prejudice_nrm geo_strength_nrm i.gop3 female i.educ age [pweight= weight] if alt_rural2==1 & nonwhite==0
margins, at(prejudice_nrm=(0(.1)1))
marginsplot, graphregion(color(white)) ylabel(,angle(horizontal)) xtitle(" " "Racial Prejudice")  ytitle("Predicted" "Place Resentment" "with 95% CIs") title("") plot1opts(lcolor(black)) ciopt(color(black))  ytitle(, orientation(horizontal)) yscale(range(0.6 0.8)) ylabel(#5) plotopts(mcolor("black")) 
graph export Figure3.png


******************************************************************
*Figure 4 Effect of White Consciousness on Place-Based Empathy*
******************************************************************
reg resent_empathy1_nrm white_grievance_nrm prejudice_nrm geo_strength_nrm i.gop3 female i.educ age [pweight= weight] if alt_rural2==0 & nonwhite==0
margins, at(white_grievance=(0(.1)1))
marginsplot, graphregion(color(white)) ylabel(,angle(horizontal)) xtitle(" " "White Consciousness")ytitle("Predicted" "Place Empathy" "with 95% CIs") title("") plot1opts(lcolor(black)) ciopt(color(black))  ytitle(, orientation(horizontal)) yscale(range(0.5 0.7)) ylabel(#5) plotopts(mcolor("black")) 
graph export Figure4.png


******************************************************************
*Figure 7 Predictors of Positive Feelings towards Rural Americans*
******************************************************************

* Feelings towards whites as predictor
reg ruralfeels whitefeels_nrm geo_strength_nrm age female educ gop3 [pweight=weight] if alt_rural2==0 & nonwhite==0
eststo wfells

* White Consciousness as predictor
reg ruralfeels white_grievance_nrm geo_strength_nrm age female educ gop3 [pweight=weight] if alt_rural2==0 & nonwhite==0
eststo wgrieve

*Make figure
coefplot (wfells, label(Feelings towards Whites) msymbol(D) mlcolor(gray) mfcolor(gray) ciopts(lcolor(gray))) (wgrieve, label(White Consciousness) msymbol(C)ciopts(lcolor(black)) mlcolor(black) mfcolor(black)), xline(0, lcolor(gs5)) drop(_cons) graphregion(color(white)) coeflabels(whitefeels_nrm = "Feelings towards Whites" geo_strength_nrm = "Strength of Geographic Identity" age = "Age" female = "Female" educ = "Education" gop3 = "Partisanship" white_grievance_nrm = "White Consciousness") order(whitefeels_nrm white_grievance_nrm geo_strength_nrm age female educ gop3) legend(region(lwidth(none))) 
graph export Figure7.png


*************************************************
*Table A4 Regression with controls and ideology *
*************************************************

** All respondents
reg resent_empathy1_nrm white_grievance_nrm prejudice_nrm c.alt_rural2##c.geo_strength_nrm i.gop3  i.educ female age conservative [pweight= weight] if nonwhite==0 

** Empathy of non-rural identifiers
reg resent_empathy1_nrm white_grievance_nrm prejudice_nrm geo_strength_nrm i.gop3 female i.educ age conservative [pweight= weight] if alt_rural2==0 & nonwhite==0

** Resentment of rural identifiers
reg resent_empathy1_nrm white_grievance_nrm prejudice_nrm geo_strength_nrm i.gop3 female i.educ age conservative [pweight= weight] if alt_rural2==1 & nonwhite==0

********************************************************************************************************
*Table A5 Predictors of Place-Based Empathy and Place-Based Resentment Index Components, with Controls *
********************************************************************************************************

*Non-rural identifiers Resources
reg rural1 white_grievance_nrm prejudice_nrm geo_strength_nrm i.gop3  i.educ female age [pweight= weight] if alt_rural2==0 & nonwhite==0

*Non-rural identifiers Influence
reg rural2 white_grievance_nrm prejudice_nrm geo_strength_nrm i.gop3  i.educ female age [pweight= weight] if alt_rural2==0 & nonwhite==0

*Non-rural identifiers Respect
reg rural3 white_grievance_nrm prejudice_nrm geo_strength_nrm i.gop3  i.educ female age [pweight= weight] if alt_rural2==0 & nonwhite==0

*Rural identifiers Resources
reg rural1 white_grievance_nrm prejudice_nrm geo_strength_nrm i.gop3  i.educ female age [pweight= weight] if alt_rural2==1 & nonwhite==0

*Rural identifiers Influence
reg rural2 white_grievance_nrm prejudice_nrm geo_strength_nrm i.gop3  i.educ female age [pweight= weight] if alt_rural2==1 & nonwhite==0

*Rural identifiers Respect
reg rural3 white_grievance_nrm prejudice_nrm geo_strength_nrm i.gop3 i.educ female age [pweight= weight] if alt_rural2==1 & nonwhite==0



************************************************************************************************************************
* Table A6: Predictors of Place Empathy and Place Resentment, with Controls and Traditional Racial Resentment Measure  *
************************************************************************************************************************

recode V202300 (-9/-1=.)(5=1)(4=2)(3=3)(2=4)(1=5), gen(trad1)
recode V202301 (-9/-1=.), gen (trad2)
recode V202302(-9/-5=.), gen (trad3)
recode V202303 (-9/-1=.) (5=1)(4=2)(3=3)(2=4)(1=5), gen(trad4)
gen trad_resentment=(trad1+trad2+trad3+trad4)
gen trad_resentment_nrml = trad_resentment/20

*All respondents
reg resent_empathy1_nrm white_grievance_nrm trad_resentment_nrml c.alt_rural2##c.geo_strength_nrm i.gop3 i.educ female  age [pweight= weight] if nonwhite==0
 
*Non-rural identifiers
reg resent_empathy1_nrm white_grievance_nrm trad_resentment_nrml geo_strength_nrm i.gop3 i.educ female  age [pweight= weight] if alt_rural2==0 & nonwhite==0

*Rural identifiers
reg resent_empathy1_nrm white_grievance_nrm trad_resentment_nrml geo_strength_nrm i.gop3  i.educ female age [pweight= weight] if alt_rural2==1 & nonwhite==0


***************************
***************************
*     Switch Data         *
***************************
***************************

clear
import delimited "Rep Files Associations Data.csv"
drop if _n < 2

* Drop non-White respondents
keep if v14 == "1"

*****************************************************************************
*Figure 5 Association between Rural and Demographic and Religious Categories*
*****************************************************************************
encode v4, gen(whites)
encode v5, gen(blacks)
encode v6, gen(latinos)
encode v7, gen(christians)
encode v8, gen(atheists)
recode whites (1=0)(2=1)(3=2)(4=3)
recode blacks (1=0)(2=1)(3=2)(4=3)
recode latinos (1=0)(2=1)(3=2)(4=3)
recode christians (1=0)(2=1)(3=2)(4=3)
recode atheists (1=0)(2=1)(3=2)(4=3)
graph bar whites blacks latinos christians atheists, graphregion(color(white)) yscale(range(0 3)) ylabel(#4) ylabel(,angle(horizontal)) bargap(16) bar(1, color(black)) bar(2, color(gray)) bar(3, color(gray)) bar(4, color(gray)) bar(5, color(gray)) legend(off) showyvars yvar(relabel(1 "Whites" 2 "Blacks" 3 "Latinos" 4 "Christians" 5 "Atheists"))  ylabel(0 "Not at all closely" 1 "Somewhat closely" 2 "Closely" 3 "Very closely") 
graph export Figure5.png



*****************************************************************************
*Figure 6 Association between Urban and Demographic and Religious Categories*
*****************************************************************************
encode v9, gen(urbanwhites)
encode v10, gen(urbanblacks)
encode v11, gen(urbanlatinos)
encode v12, gen(urbanchristians)
encode v13, gen(urbanatheists)
recode urbanwhites (1=0)(2=1)(3=2)(4=3)
recode urbanblacks (1=0)(2=1)(3=2)(4=3)
recode urbanlatinos (1=0)(2=1)(3=2)(4=3)
recode urbanchristians (1=0)(2=1)(3=2)(4=3)
recode urbanatheists (1=0)(2=1)(3=2)(4=3)
graph bar urbanwhites urbanblacks urbanlatinos urbanchristians urbanatheists, graphregion(color(white)) yscale(range(0 3)) ylabel(#4) ylabel(,angle(horizontal)) bargap(16) bar(1, color(black)) bar(2, color(gray)) bar(3, color(gray)) bar(4, color(gray)) bar(5, color(gray)) legend(off) showyvars yvar(relabel(1 "Whites" 2 "Blacks" 3 "Latinos" 4 "Christians" 5 "Atheists"))  ylabel(0 "Not at all closely" 1 "Somewhat closely" 2 "Closely" 3 "Very closely") 
graph export Figure6.png











